//1. 引入路由和Vue
import Vue from "vue";
import VueRouter from "vue-router";

//2. 引入路由组件
import Home from "../pages/Home";
import Login from "../pages/Login";

import News from "../pages/Home/News";
import Music from "../pages/Home/Music";
import Entertainment from "../pages/Home/Entertainment";

//3. 使用VueRouter这个插件
Vue.use(VueRouter);

// 解决报错
const oldpush = VueRouter.prototype.push;
VueRouter.prototype.push = function (
  location,
  onComplete = () => {},
  onAbort = () => {}
) {
  oldpush.call(this, location, onComplete, onAbort);
};

//4. 创建路由对象
const router = new VueRouter({
  routes: [
    {
      component: Home,
      path: "/home",
      name: "Home",
      //   二级路由
      children: [
        {
          path: "news",
          // 或者  path:"/home/news"
          component: News,
          name: "News",
        },
        {
          path: "music",
          component: Music,
          name: "Music",
        },
        {
          path: "entertainment",
          component: Entertainment,
          name: "Entertainment",
        },
      ],
    },
    {
      component: Login,
      path: "/login",
    },
  ],
});
//5. 把创建好的路由对象暴露出去
export default router;
